package LeetCode;

import com.sun.source.tree.Tree;

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

public class LC94 {
    public static void main(String[] args) {

    }
    public List<Integer> inorderTraversal(TreeNode root) {
        ArrayList<Integer> ans = new ArrayList<>();
        Stack<TreeNode> stack = new Stack<>();
        if(root ==null) return ans;
        TreeNode now = root;
        while (!stack.isEmpty() || now!=null){
            if(now!=null){
                stack.push(now);
                now = now.left;
            }else{
                now = stack.pop();
                ans.add(now.val);
                now = now.right;
            }
        }
        return ans;
    }
}
